"""
Data models for AI-Powered SSH Terminal
"""

from pydantic import BaseModel, validator
from typing import Dict, List, Optional, Any
from datetime import datetime
from enum import Enum

class CommandType(str, Enum):
    LINUX = "linux"
    SQL = "sql"
    DOCKER = "docker"
    KUBERNETES = "kubernetes"
    GIT = "git"

class ConnectionInfo(BaseModel):
    name: str
    hostname: str
    port: int = 22
    username: str
    password: Optional[str] = None
    key_file: Optional[str] = None
    enterprise: Optional[str] = None
    tags: List[str] = []
    description: Optional[str] = None
    
    @validator('port')
    def validate_port(cls, v):
        if not 1 <= v <= 65535:
            raise ValueError('Port must be between 1 and 65535')
        return v

class CommandRequest(BaseModel):
    query: str
    command_type: CommandType = CommandType.LINUX
    context: Optional[Dict[str, Any]] = None
    connection_id: Optional[str] = None

class AIRequest(BaseModel):
    message: str
    connection_id: Optional[str] = None
    context: Optional[Dict[str, Any]] = None

class CommandHistory(BaseModel):
    id: Optional[int] = None
    connection_id: int
    command: str
    command_type: str
    success: bool
    output: Optional[str] = None
    execution_time: Optional[float] = None
    timestamp: datetime

class ServerInfo(BaseModel):
    id: Optional[int] = None
    connection_id: int
    os_type: Optional[str] = None
    os_version: Optional[str] = None
    cpu_info: Optional[str] = None
    memory_info: Optional[str] = None
    disk_info: Optional[str] = None
    network_info: Optional[str] = None
    services: Optional[List[str]] = None
    last_updated: datetime

class AISuggestion(BaseModel):
    id: Optional[int] = None
    query: str
    suggested_command: str
    command_type: str
    success_rate: float = 0.0
    usage_count: int = 0
    created_at: datetime

class EnterpriseInfo(BaseModel):
    name: str
    connection_count: int
    common_commands: List[str]
    server_types: List[str]
    last_activity: datetime

class AnalyticsData(BaseModel):
    total_connections: int
    total_commands: int
    success_rate: float
    top_commands: List[Dict[str, Any]]
    enterprise_usage: List[EnterpriseInfo]
    recent_activity: List[Dict[str, Any]]